Skip to content

feat: show a poll's options and give a poll option its own page - #348

Merged
therealsama merged 1 commit into
mainfrom
feat/poll-options
Nov 25, 2026
Merged

therealsama merged 1 commit into
mainfrom
feat/poll-options

Conversation

@therealsama

@therealsama therealsama commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

HackerTok showed a poll as a plain text post, and a poll option's page only said it wasn't supported (#341). Both now work as on HN.

What changed

  • Polls show their options: points, share of votes, a bar, and the leader in bold. Polls with more than 12 options show the top 10 and a button for the rest (the largest has 253).
  • Options are in HN's order: most points first, ties in parts order. HN's API docs say parts is the display order, but HN's pages sort by points (27 of 28 polls checked).
  • A poll option has its own page, laid out like a comment: points, author, a link to its poll, then its text. On a phone it opens as a page, not in the swipe viewer.
  • Polls appear in user submissions and in Top's earlier days. Algolia tags them poll, so those queries ask for (story,poll).
  • Options load with the comments, from Firebase, since Algolia doesn't have their text. They're read all at once (reads share one WebSocket, so batching only adds round trips) and all-or-nothing, so no share is worked out from a partial list.
    • If the options can't be read, the comments still load, and the options are read again next time.
    • If the comments can't be read, the options still show, and the poll isn't cached.

Not included

  • Voting. HackerTok only reads HN.
  • Options on feed cards. They load with the comments.

Testing

  • npm run typecheck: passed
  • npm run lint: passed
  • npx vitest run: passed, 1216 tests
  • npx playwright test --reporter=line --retries=0: passed, 920 passed and 44 skipped across chromium, firefox, Mobile Safari and Mobile Chrome
  • Manual, against live HN on desktop and phone: polls 126809, 3746692 (37 options) and 30210378 (253 options) match HN's order; option 34180944 and its link to its poll; options or comments failing to load; user submissions; Top's earlier days.

@therealsama
therealsama force-pushed the feat/poll-options branch 3 times, most recently from f8d2d1b to 0c9cd74 Compare November 25, 2026 09:25
A poll now lists its options in HN's order, each with its points, its
share of all votes and a bar filled to that share. The leading option is
bold. A poll of more than 12 options shows its top 10 until asked, and
collapsing keeps the toggle where it was on screen.

HN's order is by points, most first, with ties in `parts` order. The API
docs call `parts` display order, but HN's pages sort by points; this held
for 27 of 28 polls checked, scale polls included. The options are sorted
(stably) where they're read, so cached and merged copies keep that order.

Options are read from the poll's `parts` while its comments are put in
HN's order. They're read all at once, not in batches: reads share one
WebSocket, so batches would only add round trips. They're read
all-or-nothing, since a missing option would misstate the others'
shares. If they can't be read, the poll shows without them and its
comments still load; a cached copy without options reads them again the
next time it's opened. If the comments can't be read, the poll still
shows its options: the failure is a CommentsError that carries the item
as read, and the hook shows it on every path that can fail (first load,
reconnect, refresh and retry). It isn't cached until its comments load.

A poll option opens on its own page, as on HN: its points, author, a
link to its poll and share, then its text, laid out like a comment, with
its paragraphs and code blocks. On the phone it opens as that page rather
than in the swipe viewer, like a job. Its text is also its tab title and
share text, where htmlToText puts a space between paragraphs.

Polls are tagged `poll`, not `story`, on Algolia, so a user's submissions
and the Top feed's earlier days now ask for `(story,poll)`.
@therealsama
therealsama merged commit 99274a8 into main Nov 25, 2026
4 checks passed
@therealsama
therealsama deleted the feat/poll-options branch November 25, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants